package org.example.leetCode;

/**
 * @author Administrator
 */
public class reversePrint {

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public int[] reversePrint(ListNode head) {
        ListNode pre = head;
        ListNode temp = head.next;
        int i = 1;
        while (temp.next != null) {
            ListNode next = temp.next;
            temp.next = pre;
            pre = temp;
            temp = next;
            i++;
        }
        int[] res = new int[i];
        int j = 0;
        while (temp != null) {
            res[j++] = temp.val;
            temp = temp.next;
        }
        return res;
    }
}
